package com.music.checkpoints.api;

import com.music.checkpoints.common.service.QuestionManager;
import com.music.checkpoints.common.utils.ResultVOUtil;
import com.music.checkpoints.common.vo.DetailVO;
import com.music.checkpoints.common.vo.ResultVO;
import com.music.checkpoints.common.vo.SubjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("/machine")
public class QuestionController {
    @Autowired
    private QuestionManager questionManager;

    @GetMapping("/questions")
    public ResultVO questions(@RequestParam("code") @NotEmpty(message = "code can not be null") String code) {
        return ResultVOUtil.success(questionManager.questions(code));
    }

    @PostMapping("/submit")
    public ResultVO submit(@RequestBody DetailVO detailVO) {
        questionManager.submitAnswer(detailVO);
        return ResultVOUtil.success();
    }

    @GetMapping("/sub_quest")
    public ResultVO subjectQuestions(@RequestParam("code") @NotEmpty(message = "code can not be null") String code,
                                     @RequestParam("type") @NotEmpty(message = "type can not be null") Integer type) {
        return ResultVOUtil.success(questionManager.subjectQuestions(code, type));
    }

    @PostMapping("/submit/subject")
    public ResultVO submitSubject(@RequestBody @Valid SubjectVO subjectVO) {
        questionManager.submitSubject(subjectVO);
        return ResultVOUtil.success();
    }
}
